package com.shopping.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shopping.entity.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    @Select("SELECT COALESCE(SUM(quantity), 0) FROM orders WHERE product_id = #{productId} AND order_status = 'COMPLETED'")
    Integer getProductSales(Long productId);
}